
<template>
  <el-dialog
    :title="formTitle"
    v-model="visible"
    width="600px"
    @close="close"
  >
    <el-form :model="form" ref="formRef" :rules="rules" label-width="100px">
      <el-form-item label="患者选择" prop="patientId">
        <el-select
          v-model="form.patientId"
          placeholder="请选择患者"
          filterable
        >
          <el-option
            v-for="patient in patients"
            :key="patient.id"
            :label="patient.name"
            :value="patient.id"
          />
        </el-select>
      </el-form-item>
      
      <el-form-item label="服务类型" prop="serviceType">
        <el-select
          v-model="form.serviceType"
          placeholder="请选择服务类型"
        >
          <el-option
            v-for="type in serviceTypes"
            :key="type.id"
            :label="type.name"
            :value="type.id"
          />
        </el-select>
      </el-form-item>
      
      <el-form-item label="时间范围" prop="timeRange">
        
        <el-date-picker
          v-model="form.timeRange"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          value-format="x"
        />
      </el-form-item>
      
      <el-form-item label="服务费用" prop="amount">
        <el-input-number
          v-model="form.amount"
          :min="0"
          :precision="2"
          controls-position="right"
        />
      </el-form-item>
    </el-form>
    
    <template #footer>
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="submit">确认</el-button>
    </template>
  </el-dialog>
 
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

const visible = ref(false)
const form = ref({
  patientId: '',
  serviceType: '',
  timeRange: [],
  amount: 0
})

const rules = {
  patientId: [{ required: true, message: '请选择患者', trigger: 'blur' }],
  serviceType: [{ required: true, message: '请选择服务类型', trigger: 'blur' }],
  timeRange: [{ required: true, message: '请选择时间范围', trigger: 'blur' }]
}

const open = () => {
  visible.value = true
}

const close = () => {
  form.value = {
    patientId: '',
    serviceType: '',
    timeRange: [],
    amount: 0
  }
  visible.value = false
}

const submit = async () => {
  // 提交逻辑
  ElMessage.success('操作成功')
  close()
}

defineExpose({ open })
</script>